package com.aglow.hyyff.base;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

import com.aglow.eventbus.bean.Event;
import com.aglow.eventbus.until.EventUntils;
import com.aglow.hyyff.bean.EventTest;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

public abstract class BaseActivity extends AppCompatActivity {
    private String TAG = "BaseActivity";

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.i(TAG, "do..fater oncreate");
        if (isRegister()) {
            EventUntils.register(this);
            Log.i("test","注册成功");
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN,sticky = true)
    public void receiveEvent(Event event) {
        Log.i("test","接收成功");
        disposeEvent(event);

    }

    protected abstract void disposeEvent(Event event);

    protected abstract boolean isRegister();

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (isRegister()){
            EventUntils.unregister(this);
        }
    }
}
